import requests
from querier.esquerier import ElasticSearchQuerier


WECHAT_INFO_URL = 'http://192.168.31.104:5000/search/v1.1/articles/info'
WEIBO_INFO_URL = 'http://192.168.31.104:5000/search/v1.1/weibo/posts/infos'


class ImgInfoQuerier(ElasticSearchQuerier):
    def __init__(self):
        super(ImgInfoQuerier, self).__init__(None, None, None)

    def _build_result(self, es_result, param):
        pass

    def _build_query(self, args):
        pass

    def search(self, args):
        source = args['source']
        article_id = args['article_id']
        res = {}
        if source == 'wechat' and article_id:
            payload = {
                'ids': [article_id]
            }
            out = requests.post(WECHAT_INFO_URL, json=payload, timeout=200).json()

            out = out['infos'][0]
            res = {
                'url': out['url'],
                'text': out['abstract'],
                'title': out['title']
            }

        elif source == 'weibo' and article_id:
            payload = {
                'weibo_ids': [article_id]
            }

            out = requests.post(WEIBO_INFO_URL, json=payload, timeout=200).json()

            out = out['infos'][0]
            res = {
                'url': out['url'],
                'text': out['summary'],
                'title': out['summary']

            }
        else:
            pass

        return res



